package jms;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jms.*;

@Component("jmsSender")
public class JmsSender implements Sender{

    @Resource(name="jmsTemplate")
    private JmsTemplate jmsTemplate;
    @Resource
    private Queue queue;


    public int send(String msg) {
        this.jmsTemplate.send(this.queue, new MyMessageCreator(msg));
        return 1;
    }
    class MyMessageCreator implements MessageCreator{
        String msg;
        MyMessageCreator(String msg){
            this.msg = msg;
        }

        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(msg);
        }
    }
}
